﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CS_BEGINNER_TO_PROFICIENT.STD.DelegatedSTD
{
    public class DelegatedSTD_P1
    {
        public static void Execute()
        {
            List<Person> peoples = new List<Person>
            {
                new Person { Name = "Alice", Age = 30 },
                new Person { Name = "Bob", Age = 25 },
                new Person { Name = "Charlie", Age = 35}
            };

            // Linq 方法语法
            var result = peoples.Where(p => p.Age > 30);
            Console.WriteLine(result.GetType());
            foreach (var i in result)
            {
                Console.WriteLine($"{i.Name} is {i.Age} years old.");
            }

            // Linq 查询语法
            var res = from person in peoples where person.Age > 30 select person;
            foreach (var e in res)
            {
                Console.WriteLine($"{e.Name} is {e.Age} years old.");
            }
        }
    }

    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }
}
